#include<iostream>
#include<pthread.h>
#include<unistd.h>
#include<sched.h>
#include"Lock.hpp"
int ticket=1000;
LockModule::Mutex mutex;
void* GetTicket(void* arg)
{
    while(true)
    {
        LockModule::LockGuard guard(mutex);
        if(ticket>0)
        {
            usleep(1000);
            std::cout<<"获取到门票:"<<ticket--<<std::endl;
        }
        else
        {
            break;
        }
    }
    return nullptr;
}
int main()
{
    pthread_t t1,t2,t3,t4;
    pthread_create(&t1,nullptr,GetTicket,nullptr);
    pthread_create(&t2,nullptr,GetTicket,nullptr);
    pthread_create(&t3,nullptr,GetTicket,nullptr);
    pthread_create(&t4,nullptr,GetTicket,nullptr);
    pthread_join(t1,nullptr);
    pthread_join(t2,nullptr);
    pthread_join(t3,nullptr);
    pthread_join(t4,nullptr);
    return 0;
}